package com.clz.hyperit.dao.impl;

import java.util.List;

import org.hibernate.Session;
import org.springframework.stereotype.Repository;

import com.clz.hyperit.dao.CommentDao;
import com.clz.hyperit.entity.Comment;
import com.clz.hyperit.vo.PageInfo;
@Repository("commentDao")
public class CommentDaoImpl extends BaseDaoImpl<Comment> implements CommentDao {

	
	@SuppressWarnings("unchecked")

	public List<Comment> getBytarget_idAndType(PageInfo pageInfo,Integer target_id, Integer type) {
		String hql = "from Comment where target_id = :target_id and type = :type order by createtime desc";
		List<Comment> list = getCurrentSession().createQuery(hql)
		.setInteger("target_id", target_id).setInteger("type", type)
		.setFirstResult(
				(pageInfo.getIndexPageNum() - 1) * pageInfo.getSize())
		.setMaxResults(pageInfo.getSize()).list();
		
		String hql2 = "select count(*) from Comment where target_id = :target_id and type = :type";

		// 获得表中总的条目数目
		Object uniqueResult = getCurrentSession().createQuery(hql2)
				.setInteger("target_id", target_id).setInteger("type",type).uniqueResult();
		Long intValue = (new Integer(uniqueResult.toString())).longValue();
		pageInfo.setTotalCount(intValue);
		return list;

	}


}
